package org.example.diet_compass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.diet_compass.domain.Users;
import org.example.diet_compass.mapper.UsersMapper;
import org.example.diet_compass.service.UsersService;
import org.springframework.stereotype.Service;

/**
* @author 86135
* @description 针对表【users(用户基本信息表)】的数据库操作Service实现
* @createDate 2025-03-02 15:03:07
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService {

    @Resource
    UsersMapper usersMapper;

    @Override
    public Users getUser(String openid) {
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("openid", openid);
        return usersMapper.selectOne(queryWrapper);
    }

    @Override
    public void insertUser(Users user) {
        usersMapper.insert(user);
    }

    @Override
    public void updateUserInfo(Users user) {

        int i = usersMapper.updateById(user);

    }

    @Override
    public Users getUserById(int id) {
        return usersMapper.selectById(id);
    }

    @Override
    public String getAvatarUrlById(int userId) {
        return usersMapper.getAvatarUrlById(userId);
    }

    @Override
    public void updateUserAvatar(int userId, String fileUrl) {
        usersMapper.updateAvatarById(userId, fileUrl);
    }
}




